<template>
  <div>
    <div class="grid-content bg-purple">
      <div class="content content2">
        <div class="header">
          <div class="title">
            合作商点位数Top5
          </div>
        </div>
        <div class="body">
          <el-row>
            <el-col :span="17"><div class="grid-content bg-purple">
              <div class="echarts">
                <div id="pie" />
              </div>
            </div>
            </el-col>
            <el-col :span="7">
              <div class="grid-content bg-purple-light">
                <div class="collect">
                  <div class="count">{{ count }}</div>
                  <div class="name">点数位</div>
                  <div class="count count2">{{ nodeCollectList.length }}</div>
                  <div class="name">合作商数</div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { nodeCollect } from '@/api'
export default {
  data() {
    return {
      nodeCollectList: [],
      count: null
    }
  },
  async mounted() {
  },
  async created() {
    const res = await nodeCollect()
    // console.log(res.data)
    this.nodeCollectList = res.data
    this.changetype()
    this.count = res.data.reduce((sum, item) => sum + item.value, 0)
    console.log(this.count)
  },
  methods: {
    // 饼图
    changetype() {
      // 获取组件实例
      const machart = this.$echarts.init(document.getElementById('pie'))
      // 设置配置项
      const option = {
        tooltip: {
          trigger: 'item',
          formatter: '{b} <br/> 总站比 {d}%'
        },
        series: [{
          type: 'pie',
          radius: [30, 100],
          center: ['50%', '50%'],
          roseType: 'radius',
          data: this.nodeCollectList
        }]
      }
      // 复制
      machart.setOption(option)
      // 根据页面大小自动响应图表大小
      window.addEventListener('resize', function() {
        machart.resize()
      })
    }
  }

}
</script>

<style lang="scss" scoped>
@import "~@/styles/count.scss";

.content2 {
  background-color: #fff !important;
  background-image: none !important;
}

#pie {
  width: 580px;
  height: 284px;
}

.echarts {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  padding: 0px;
  margin: 0px;
  border-width: 0px;
  cursor: default;
}
.collect{
  width: 154px;
    height: 230px;
    padding-top: 47px;
    padding-left: 38px;
    background: linear-gradient(135deg,transparent,#f8f8f9 0) 0 0,linear-gradient(-135deg,transparent 12px,#f8f8f9 0) 100% 0,linear-gradient(-45deg,transparent,#f8f8f9 0) 100% 100%,linear-gradient(45deg,transparent 12px,#f8f8f9 0) 0 100%;
    background-size: 50% 50%;
    background-repeat: no-repeat;
    .count{
      height: 33px;
    font-size: 24px;
    font-family: PingFangSC-Semibold,PingFang SC;
    font-weight: 600;
    color: #072074;
    line-height: 33px;
    }
    .count2{
      margin-top: 20px;
    }
    .name{
    height: 17px;
    margin-top: 6px;
    font-size: 12px;
    font-family: PingFangSC-Regular,PingFang SC;
    font-weight: 400;
    color: #000412;
    line-height: 17px;
    }
}
</style>
